*****************************************************************************
*** Replication Do-file (Appendix) ******************************************
*****************************************************************************

clear

use data1-46.dta

*********************
*** Data Cleaning ***
*********************


*** Data from a particular week is dropped if:
// (1) If one of the consetants is disqualified (dummy variable "disqualified")
// (2) If one of the contestans could not finish the menu (dummy variable "unfinished_menu")
// (3) If the groom instead of the bride participated (dummy variable "groom")

drop if disqualified==1
drop if unfinished_menu==1
keep if week>19


*** Renumber weeks
egen week_new=group(week) 
replace week=week_new
drop week_new

save data_analysis1-46.dta, replace


***********************************************
*** Table A3 and A4 - Descriptive Statistics **
***********************************************

tabstat points if !missing(points), stat(mean sd min max)
tabstat cookfirst cook_second cook_third cook_fourth cook_fifth already_cooked if !missing(points), stat(mean sd min max)
tabstat host if !missing(points), stat(mean sd min max)

tabstat host if cookfirst==1 & i_cook==1,stat(mean sd min max)
tabstat host if cook_second==1 & i_cook==1,stat(mean sd min max)
tabstat host if cook_third==1 & i_cook==1,stat(mean sd min max)
tabstat host if cook_fourth==1 & i_cook==1,stat(mean sd min max)
tabstat host if cook_fifth==1 & i_cook==1,stat(mean sd min max)

tabstat total if cookfirst==1 & i_cook==1,stat(mean sd min max)
tabstat total if cook_second==1 & i_cook==1,stat(mean sd min max)
tabstat total if cook_third==1 & i_cook==1,stat(mean sd min max)
tabstat total if cook_fourth==1 & i_cook==1,stat(mean sd min max)
tabstat total if cook_fifth==1 & i_cook==1,stat(mean sd min max)

tabstat total, stat(mean sd min max)
tabstat overall, stat(mean sd min max)


***************************************
*** Table A5 and Figure A2 - Distribution of Points***
***************************************

tab points 
set scheme s1mono
hist points 

bysort cook: tab points


*************************************************
*** Table A6 - Evaluator Fixed Effects Estimation
*************************************************

** Create a unique ID for every contestant-week combination 
egen unique_evaluator_id = group(week evaluator)

xtset unique_evaluator_id

*** Naive Model - Column (1) without "already cooked"

xtreg points cook_second cook_third cook_fourth cook_fifth host , fe cluster(week)

*** Full Model - Column (2) with "already cooked"

xtreg points cook_second cook_third cook_fourth cook_fifth already_cooked host , fe cluster(week)

*** Excluding Host - Column (3)

xtreg points cook_second cook_third cook_fourth cook_fifth already_cooked , fe cluster(week)


*********************************************************
*** Table A7 and Figure A3 - Model with Interaction Terms
*********************************************************
set scheme s1mono
*** Create a "cook order" variable from dummies
gen cook_order = 1  
replace cook_order = 2 if cook_second == 1
replace cook_order = 3 if cook_third == 1
replace cook_order = 4 if cook_fourth == 1
replace cook_order = 5 if cook_fifth == 1

*** Regression with interaciton terms
reg points i.cook_order##i.already_cooked host i.week, cluster(week)

*** Calculate the predictions
margins cook_order, over(already_cooked)

*** Figure A3 - Margins Plot
marginsplot, x(cook_order) noci ///
    title("Decomposition of Order Effects") ///
    ytitle("Predicted Score") ///
    legend(label(1 "Evaluator Has Not Cooked") label(2 "Evaluator Has Already Cooked")) 


*********************************************
*** Table A8 - FE vs. Mixed Models  **********
*********************************************

xtset unique_evaluator_id

*** Main Model (FE) - Column (1)
xtreg points i.cook_order i.already_cooked host, fe cluster(week)


*** Hierarchical (Mixed) Model - Column (2)
mixed points i.cook_order i.already_cooked host || week: || unique_evaluator_id:, std


*** Random Effects Model - Column (3)
xtreg points i.cook_order i.already_cooked host i.week, re cluster(week)

*********************************************
*** Table A9 - Probability of Winning *******
*********************************************

*** Create a tag that equals 1 for exactly one row per contestant per week
egen cook_tag = tag(week cook)

bysort week: egen maxpoints=max(overall)
gen winner=1 if overall==maxpoints
replace winner=0 if winner==.

*** Linear Probability Model - Column (1)
reg winner cook_second cook_third cook_fourth cook_fifth host i.week if cook_tag==1, cluster(week)

*** Logit Regression - Column (2)	
logit winner cook_second cook_third cook_fourth cook_fifth host i.week if cook_tag==1, cluster(week)	
margins, dydx(*)

*** Probit Regression - Column (3)	
probit winner cook_second cook_third cook_fourth cook_fifth host i.week if cook_tag==1, cluster(week)		
margins, dydx(*)


**************************************************
*** Table A10 - Evidence on Host Scoring Behaviour
**************************************************

preserve

*** Collapse to get 1 row per cook
*** peer_avg: calculated from the 'points' column
*** host_score: takes the 'host' column (which is constant for that cook)
*** cook_order variables: keep the max (since 1 is present in the group)
collapse (mean) peer_avg=points (first) host_score=host ///
         (max) cookfirst cook_second cook_third cook_fourth, ///
         by(week cook)
		 
*** Regress Host Score on Peer Average - Panel (A)
reg host_score peer_avg i.week, cluster(week)


*** Standard Deviations of Scores - Panel (B)
tabstat peer_avg, stat(sd mean min max)
tabstat host_score, stat(sd mean min max)	

restore

**************************************************
*** Table A11 - Reciprocity and Strategic Robustness
**************************************************

*** Prepare the lookup data
preserve

keep week cook evaluator points
rename points score_received

*** swap ID's: We want to match this to the "Reverse" pair.
*** If the original row is "Cook A, Evaluator B", we want to save it as
*** a lookup for when "Cook B" is being evaluated by "Evaluator A".
rename cook temp_eval
rename evaluator temp_cook

rename temp_eval evaluator
rename temp_cook cook

save "reciprocity_lookup.dta", replace

restore


*** We pull that information back into the main dataset
merge 1:1 week cook evaluator using "reciprocity_lookup.dta", keepusing(score_received)

* Clean up
drop if _merge == 2  
drop _merge

replace score_received = . if already_cooked == 0

*** Restricted Sample - Reciprocity Only - Column (1)
reg points score_received host i.week, cluster(week)


*** Full Sample with mean imputation - Column (2)
gen score_received_imputed = score_received
replace score_received_imputed = 3.84 if already_cooked == 0

xtset unique_evaluator_id

xtreg points cook_second cook_third cook_fourth cook_fifth ///
      already_cooked score_received_imputed host, fe cluster(week)


*** Compliant Evaluators only - Column (3) 

preserve

gen non_compliant_score = (points < 3 | points > 6) & !missing(points)

*** Check if the evaluator EVER broke the rule during the week
bysort unique_evaluator_id: egen evaluator_broke_rule = max(non_compliant_score)

keep if evaluator_broke_rule == 0

drop if missing(points)

xtreg points cook_second cook_third cook_fourth cook_fifth ///
      i.already_cooked score_received_imputed host, fe cluster(week)
      
restore


******************************************************************
*** Table A12 - Testing for Learning Effects and Time Trends *****
******************************************************************
clear

use data_analysis.dta
*** Column (1): Evaluator Fixed Effects with Learning Interaction
*** We use (week - 1) so the main effect of "already_cooked" is interpreted 
*** as the effect at the start of the sample period (Week 1).

gen week_centered = week - 1
gen learning_interaction = already_cooked * week_centered

egen unique_evaluator_id = group(week evaluator)

xtset unique_evaluator_id

xtreg points cook_second cook_third cook_fourth cook_fifth ///
      already_cooked learning_interaction host, fe cluster(week)


*** Column (2): Linear Time Trend OLS
*** This checks for general score inflation while controlling for strategic variables.

reg points cook_second cook_third cook_fourth cook_fifth ///
    already_cooked host week, cluster(week)














